package com.dailyblue.java.project.smbms.logistics.listener;

import com.alibaba.fastjson.JSONArray;
import com.dailyblue.java.spring.project.smbms.commons.bean.Logistics;
import com.dailyblue.java.spring.project.smbms.commons.bean.Orders2;
import com.dailyblue.java.spring.project.smbms.commons.service.LogisticsService;
import org.apache.rocketmq.spring.annotation.MessageModel;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
@RocketMQMessageListener(topic = "ORDER", messageModel = MessageModel.BROADCASTING, consumerGroup = "group_b")
public class ConsumerListener implements RocketMQListener<String> {
    @Resource
    private LogisticsService logisticsService;

    @Override
    public void onMessage(String s) {
        Orders2 o = JSONArray.parseObject(s, Orders2.class);
        Logistics logistics = new Logistics();
        logistics.setAddress(o.getAddress());
        logistics.setPhone(o.getPhone());
        logistics.setBid(o.getBid());
        logisticsService.saveLogistics(logistics);
    }
}
